//
//  LSChatTopView.m
//  LookScore
//
//  Created by wr on 2017/12/11.
//  Copyright © 2017年 ChongQingXunTiCompany. All rights reserved.
//

#define controlWidth (self.width-LSSpaceLeftWidth2*2-10)/3
#import "LSChatTopView.h"
#import <UIButton+WebCache.h>
#import "LSTopicCircleModel.h"
@implementation LSChatTopView

- (instancetype)initWithFrame:(CGRect)frame{
    self=[super initWithFrame:frame];
    if (self) {
        self.backgroundColor = LSTitleWhiteColor;
//        [self addContentViewWith:array];
    }
    return self;
    
   
}

- (void)setDataArray:(NSMutableArray *)dataArray{
    _dataArray = dataArray;
    [self addContentViewWith:dataArray];
}

- (void)addContentViewWith:(NSMutableArray *)array{
   //防止重复 先移除所有的子视图
    [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
//    NSArray *imgArray=@[@"[ChatBattlefield]",@"ChatSpinage",@"ChatSuggest"];
    CGFloat allWidth=LSSpaceLeftWidth2;
    for (int i=0; i<array.count; i++) {
        LSTopicCircleModel * model = array[i];
        UIButton *button=[UIButton new];
        button.tag=i;
        
        [button sd_setImageWithURL:[NSURL URLWithString:model.ImageUrl] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"ChatBattlefield"] options:SDWebImageRefreshCached];
//        [button setImage:[UIImage imageNamed:imgArray[i]] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(buttonEvent:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:button];
        button.sd_layout
        .leftEqualToView(self).offset(allWidth)
        .topEqualToView(self).offset(9)
        .widthIs(controlWidth)
        .heightIs(LSAutoVlaue(57, LSScreenWidth));
        allWidth+=(controlWidth+5);
        
        UILabel *titleLab=[[UILabel alloc]init];
        titleLab.font=LSFontSize10;
        titleLab.text=@"热门文章";
        titleLab.textColor=LSTitleGrayColor2;
        titleLab.textAlignment=NSTextAlignmentLeft;
        [self addSubview:titleLab];
        titleLab.sd_layout
        .leftEqualToView(button)
        .topSpaceToView(button, 5)
        .heightIs(20)
        .autoWidthRatio(2.5);
        
        UILabel *titleReadLab=[[UILabel alloc]init];
        titleReadLab.font=LSFontSize10;
        titleReadLab.text= [NSString stringWithFormat:@"%ld",model.HotCount];
        titleReadLab.textAlignment=NSTextAlignmentRight;
        titleReadLab.textColor=LSTitleGrayColor2;
        [self addSubview:titleReadLab];
        titleReadLab.sd_layout
        .leftSpaceToView(titleLab, 0)
        .topSpaceToView(button, 5)
        .rightEqualToView(button)
        .heightIs(20);
    }
   
    
    
    
}


-(void)buttonEvent:(UIButton *)sender{
    if (self.chatTopBlock) {
        self.chatTopBlock(sender.tag);
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
